package com.qf.controller;

import com.qf.entity.TbAdmin;
import com.qf.service.AdminService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName AdminController
 * @Description
 * @Author lanzhike
 * @Date 2023/7/18 8:55
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * 管理员登录
     * @param map
     * @param request
     * @return
     */
    @PostMapping("/login")
    public ResultMsg login(@RequestBody Map map, HttpServletRequest request){
        String name = (String) map.get("name");
        String password= (String) map.get("password");
        return adminService.login(name,password,request);
    }

    /**
     * 根据管理员昵称查询管理员信息
     * @param name
     * @return
     */
    @GetMapping("/findOne")
    public ResultMsg findOne(String name){
        return adminService.findByName(name);
    }

    /**
     *修改管理员信息
     * @param tbAdmin
     * @return
     */
    @PostMapping("/update")
    public ResultMsg update(@RequestBody TbAdmin tbAdmin){
        return adminService.updateAdmin(tbAdmin);
    }

    /**
     * 修改密码
     * @param map
     * @return
     */
    @PostMapping("/uppass")
    public ResultMsg uppass(@RequestBody Map map){
        int adminId = (int) map.get("adminId");
        String oldPass= (String) map.get("oldPass");
        String newPass= (String) map.get("newPass");
        String rePass= (String) map.get("rePass");
        return adminService.setPass(adminId,oldPass,newPass,rePass);
    }
}
